﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Form5
    Sub Carga_Estados()
        Dim SQL As String = "select * from Estado order by Cod_Estado ASC"
        Dim da As SqlDataAdapter
        Dim dt As New DataTable
        Try
            da = New SqlDataAdapter(SQL, nCnn)
            da.Fill(dt)
            ComboBox1.Items.Clear()
            For i = 0 To dt.Rows.Count - 1
                ComboBox1.Items.Add(RTrim(dt.Rows(i)("Cod_Estado")) & " - " & RTrim(dt.Rows(i)("Descripcion")))
            Next
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call Carga_Estados()
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim Estado As String = Mid(ComboBox1.Text, 1, 2)
        Dim SQL As String = "SELECT l.Cod_licitacion, l.Descripcion, l.Fecha_registro, l.Fecha_inicio, l.Fecha_fin, l.Responsable, e.Descripcion'Estado' FROM Licitacion l " & _
                            " INNER JOIN Estado e ON e.Cod_Estado=l.Cod_Estado" & _
                            " WHERE l.Cod_Estado='" & Estado & "'" & " ORDER BY l.Cod_licitacion ASC"
        Dim da As SqlDataAdapter
        Dim dt As New DataTable
        Try
            da = New SqlDataAdapter(SQL, nCnn)
            da.Fill(dt)
            ListView1.Items.Clear()
            For i = 0 To dt.Rows.Count - 1
                Dim Itm = ListView1.Items.Add(RTrim(dt.Rows(i)("Cod_licitacion")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Descripcion")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_registro")))
                If IsDBNull(dt.Rows(i)("Fecha_inicio")) Then
                    Itm.SubItems.Add("")
                Else
                    Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_inicio")))
                End If
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_fin")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Responsable")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Estado")))
            Next
            ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim SQL As String = "SELECT l.Cod_licitacion, l.Descripcion, l.Fecha_registro, l.Fecha_inicio, l.Fecha_fin, l.Responsable, e.Descripcion'Estado' FROM Licitacion l " & _
                           " INNER JOIN Estado e ON e.Cod_Estado=l.Cod_Estado" & _
                           " WHERE l." & ComboBox2.Text & " BETWEEN '" & Format(CType(DateTimePicker1.Value, Date), "MM/dd/yyyy") & "'" & " AND '" & Format(CType(DateTimePicker2.Value, Date), "MM/dd/yyyy") & "'" & " ORDER BY l.Cod_licitacion ASC"
        Dim da As SqlDataAdapter
        Dim dt As New DataTable
        Try
            da = New SqlDataAdapter(SQL, nCnn)
            da.Fill(dt)
            ListView1.Items.Clear()
            For i = 0 To dt.Rows.Count - 1
                Dim Itm = ListView1.Items.Add(RTrim(dt.Rows(i)("Cod_licitacion")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Descripcion")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_registro")))
                If IsDBNull(dt.Rows(i)("Fecha_inicio")) Then
                    Itm.SubItems.Add("")
                Else
                    Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_inicio")))
                End If
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_fin")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Responsable")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Estado")))
            Next
            ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub ListView1_DoubleClick(sender As Object, e As EventArgs) Handles ListView1.DoubleClick
        For i = 0 To ListView1.Items.Count - 1
            If ListView1.Items(i).Selected = True Then
                Cod_Lic = ListView1.Items(i).SubItems(0).Text
                Form9.MdiParent = MDIParent1
                Form9.Show()
                Exit For
            End If
        Next
    End Sub

    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
     
    End Sub
End Class